Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - [VB .NET] Stampa dati di una listbox
Forum - C# / VB.NET - [VB .NET] Stampa dati di una listbox

Avatar
marco_grillo (Member)
Rookie


Messaggi: 33
Iscritto: 22/04/2009

Segnala al moderatore
Postato alle 21:34
Venerdì, 25/09/2009
Salve,
   ho problemi durante la stampa di dati di una listbox.
In poche parole mi stampa solo una pagina!

Ecco il codice:

Codice sorgente - presumibilmente VB.NET

  1. Private Sub cmdStampa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStampa.Click
  2.         txtStampa.Text = UCase(txtStampa.Text)
  3.         lblOk.Text = ""
  4.  
  5.         AddHandler pd.PrintPage, AddressOf Me.pd_PrintElenco
  6.  
  7.         If lstSomma.Items.Count <> 0 Then
  8.             If txtStampa.Text <> "" Then
  9.                 Try
  10.                     AddHandler pd.PrintPage, AddressOf Me.pd_PrintElenco
  11.                     pd.Print()
  12.                 Catch ex As Exception
  13.                     MessageBox.Show(ex.Message & Environment.NewLine & ex.StackTrace)
  14.                 End Try
  15.  
  16.                 lblOk.Text = "OK"
  17.             Else
  18.                 If MsgBox("La stampa è senza titolo, continuare?", MsgBoxStyle.YesNo, "CONTINUARE STAMPA?") = MsgBoxResult.Yes Then
  19.                     Try
  20.                         AddHandler pd.PrintPage, AddressOf Me.pd_PrintElenco
  21.                         pd.Print()
  22.                     Catch ex As Exception
  23.                         MessageBox.Show(ex.Message & Environment.NewLine & ex.StackTrace)
  24.                     End Try
  25.  
  26.                     lblOk.Text = "OK"
  27.                 End If
  28.             End If
  29.         Else
  30.             MsgBox("Nessuna battuta da stampare", MsgBoxStyle.Information, "BATTUTE INESISTENTI")
  31.             txtNum.Select()
  32.         End If
  33.     End Sub
  34.  
  35.  
  36.  
  37.  
  38.     Private Sub pd_PrintElenco(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
  39.         Dim printFont As New Font("Arial", 13)
  40.         Dim yPos As Long = 30
  41.         Dim xPos As Long = 30
  42.  
  43.         ev.Graphics.DrawString(txtStampa.Text, printFont, Brushes.Black, xPos, yPos, New StringFormat())
  44.         yPos = yPos + Font.Height
  45.         yPos = yPos + Font.Height
  46.  
  47.         printFont = New Font("Arial", 11)
  48.         Try
  49.             For x As Integer = 0 To lstSomma.Items.Count - 1
  50.                 ev.Graphics.DrawString(lstSomma.Items(x).ToString, printFont, Brushes.Black, xPos, yPos, New StringFormat())
  51.                 yPos = yPos + Font.Height
  52.             Next
  53.  
  54.             yPos = yPos + Font.Height
  55.             yPos = yPos + Font.Height
  56.             ev.Graphics.DrawString("Totale €: " + lblSomma.Text, printFont, Brushes.Black, xPos, yPos, New StringFormat())
  57.             yPos = yPos + Font.Height
  58.             ev.Graphics.DrawString("Numero battute: " + lblBatt.Text, printFont, Brushes.Black, xPos, yPos, New StringFormat())
  59.             yPos = yPos + Font.Height
  60.             ev.Graphics.DrawString("Data e ora di stampa: " & Today & " - " & TimeOfDay, printFont, Brushes.Black, xPos, yPos, New StringFormat())
  61.         Catch ex As Exception
  62.             MessageBox.Show(ex.Message & Environment.NewLine & ex.StackTrace)
  63.         End Try
  64.     End Sub



Grazie.

PM Quote
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 15:07
Lunedì, 28/09/2009
Non mi sembra che ci sia scritto da nessuna parte di continuare a stampare su un'altra pagina nel caso in cui i dati siano troppi... Devi essere tu a controllare dove sei arrivato (con yPos): una volta raggiunta la fine della pagina, devi fermare le operazioni di stampa/disegno e rimandarle all'evento successivo. Per far questo devi impostare e.HasMorePages su True (questo obbliga l'oggetto a lanciare un'altra volta lo stesso evento PrintPage), e devi usare una variabile Static che tenga in memoria il punto in cui sei arrivato a stampare. Dovresti rendere Static anche il font, perchè è inutile creare un nuovo oggetto font ogni volta che inizia una nuova stampa...

PM Quote